<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Yy</title>
</head>

<body>
    <h1><span id="spanId">5</span>秒钟之后跳转到百度</h1>
    <script>
        // 3. 实现一个五秒后跳转至百度的效果
        var x = 5;

        function fun() {
            var span = document.getElementById("spanId");
            span.innerHTML = x;
            x--;
            if (x == 0) {
                location.href = "https://www.baidu.com/";
            }
            window.setTimeout("fun()", 1000);
        }
        fun();
    </script>
</body>

</html>